var currentUserId = "";
var currentUserName = "";
var currentCourseId = "";
var currentCourseName = "";
var currentAssignmentId = "";
var currentAssignmentName = "";
var currentActivityId = "";
var currentActivityName = "";
// 以下是图表产生
var ctimes=0;
var bctimes=0;
var score=0;
var commentType="";
$(function(){
	$.ajax({
		url:'/pad/getSessionUser',
		success:function(user){
			currentUserId = user.id;
			currentUserName = user.realname;
			$("#user").html(user.realname+' <span class="caret"></span>');
		}
	});
	allCurrentActivityView();
});
function manageConst(courseId,courseName,assignmentId,assignmentName){
	currentCourseId = courseId?courseId:"";
	currentCourseName = courseName?courseName:"";
}
function allCurrentActivityView(){
	$('#breadcrumb').html('<li class="active">首页</li>');
	$('#toolbar').html('<button class="btn btn-info" onclick="javascript:courseListView();"><span class="glyphicon glyphicon-list-alt"></span> 我的课程列表</button><h3 class="pull-left">正在进行的活动</h3>');
	$('#visions').html('');
	$('#data-table').bootstrapTable('destroy');
	$('#data-table').bootstrapTable({
	    url: 'activity/getAllCurrentActivity',
	    undefinedText:'',
	    striped:true,
	    toolbar:'#toolbar button',
	    toolbarAlign:'right',
	    idField:'id',
	    columns: [
	    	{field: 'activityName',title: '活动名称',width:200}, 
	    	{field: 'description',title: '活动简介'}, 
	    	{field: 'startDate',title: '开始时间',width:100}, 
	    	{field: 'endDate',title: '结束时间',width:100}, 
	    	{field: 'assignmentName',title: '所属作业',width:200}, 
	    	{field: 'courseName',title: '所属课程',width:200},
	    	{field: 'op',title: '操作',width:180,formatter:function(value,row,index){
	    		if(row.activityType=="COMMENT"){
    				return '<a href="/pad/comment.html?assignmentId='+row.assignmentId+'" target="_blank" class="btn btn-info btn-xs">组内互评</a>';
    			}else if(row.activityType=="FEEDBACK"){
    				var htmlStr = '<div class="btn-group"><button class="btn btn-info btn-xs dropdown-toggle" type="button" id="dropdownMenu'+index+'" data-toggle="dropdown">组间互评<span class="caret"></span></button><ul class="dropdown-menu" style="position:relative;" role="menu" aria-labelledby="dropdownMenu'+index+'">';
    				$.ajax({
    					url:'/pad/assignment/getCommentAssignmentPad?activityId='+row.id,
	    	    		async: false,
    					success:function(data){
    						for(var i=0;i<data.assignmentPads.length;i++){
    							if(data.assignmentPads[i]!=null)
    							htmlStr += '<li role="presentation"><a role="menuitem" tabindex="-1" target="_blank" href="/pad/feedback.html?assignmentPadId='+data.assignmentPads[i].id+'">'+data.assignmentPads[i].groupName+'</a></li>';
    						}
    					}
    				});
    				htmlStr +='</ul></div> <a href="/pad/edit?assignmentId='+row.assignmentId+'" target="_blank" class="btn btn-info btn-xs">回评</a>';
    				return htmlStr;
    			}else{
    				return '<a href="/pad/edit?assignmentId='+row.assignmentId+'" target="_blank" class="btn btn-info btn-xs">编辑</a>';
    			}
	    	}}]
	});
}
function courseListView(){
	$('#nav li:first').addClass('active');
	$('#breadcrumb').html('<li><a href="/pad">首页</a></li><li class="active">课程列表</li>');
	$('#visions').html('');
	$('#toolbar').html('<h3>课程列表</h3>');
	$('#data-table').bootstrapTable('destroy');
	$('#data-table').bootstrapTable({
	    url: 'course/getCourses',
	    undefinedText:'',
	    striped:true,
	    idField:'id',
	    columns: [
	    	{field: 'year',title: '年份',width:100}, 
	    	{field: 'courseName',title: '课程名'},
	    	{field: 'op',title: '操作',width:100,formatter:function(value,row,index){
	    		return '<a href="javascript:assignmentListView(\''+row.id+'\',\''+row.courseName+'\');" class="btn btn-info btn-xs">进入</a>';
	    	}}]
	});
}
function assignmentListView(courseId,courseName){
	manageConst(courseId,courseName);
	$('#breadcrumb').html('<li><a href="/pad">首页</a></li><li><a href="javascript:courseListView();">课程列表</a></li><li class="active">'+courseName+'</li>');
	$('#visions').html('');
	$('#toolbar').html('<h3>作业列表</h3>');
	$('#data-table').bootstrapTable('destroy');
	$('#data-table').bootstrapTable({
	    url: 'assignment/getAssignments?courseId='+courseId,
	    undefinedText:'',
	    striped:true,
	    idField:'id',
	    columns: [
	    	{field: 'assignmentName',title: '作业名称'},
	    	{field: 'description',title: '作业描述'},
	    	{field: 'startDate',title: '开始时间',width:100},
	    	{field: 'endDate',title: '结束时间',width:100},
			{field: 'op',title: '操作',width:100,formatter:function(value,row,index){
				return '<a href="javascript:activityListView(\''+row.id+'\',\''+row.assignmentName+'\');" class="btn btn-info btn-xs">进入</a>';
			}}]
	});
}
function activityListView(assignmentId,assignmentName){
	manageConst(currentCourseId,currentCourseName,assignmentId,assignmentName);
	$('#breadcrumb').html('<li><a href="/pad">首页</a></li><li><a href="javascript:courseListView();">课程列表</a></li><li><a href="javascript:assignmentListView(\''+currentCourseId+'\',\''+currentCourseName+'\');">'+currentCourseName+'</a></li><li class="active">'+assignmentName+'</li>');
	$('#visions').html('');
	$('#toolbar').html('<h3>活动列表</h3>');
	$('#data-table').bootstrapTable('destroy');
	$('#data-table').bootstrapTable({
	    url: 'activity/getActivities?assignmentId='+assignmentId,
	    undefinedText:'',
	    idField:'id',
	    sortName:'startDate',
	    rowStyle:function rowStyle(row, index) {
	    	if(new Date(row.startDate)>new Date()){
	    		return {
					css: {"color": "#fff","background-color": "#bcd2d8"}
				};
    		}else if(new Date(row.startDate)<=new Date() &&　new Date(row.endDate)>new Date()){
    			return {
					css: {"color": "#fff","background-color": "#6de66b"}
				};
    		}else{
    			return {
					css: {"color": "#fff","background-color": "#bbb"}
				};
    		}
	    	
		},
	    columns: [
	    	{field: 'activityType',title: '活动状态',width:100,formatter:function(value,row,index){
	    		if(new Date(row.startDate+' 00:00:00')>new Date()){
	    			return '即将开始';
	    		}else if(new Date(row.startDate+' 00:00:00')<=new Date() &&　new Date(row.endDate+' 00:00:00')>new Date()){
	    			return '正在进行';
	    		}else{
	    			return '已结束';
	    		}
	    	}},
	    	{field: 'activityName',title: '活动名称',width:'200'},
	    	{field: 'description',title: '活动描述'},
	    	{field: 'startDate',title: '开始时间',width:100},
	    	{field: 'endDate',title: '结束时间',width:100},
	    	{field: 'showVision',title: '群体感知显示',width:20,align:'center',formatter:function(value,row,index){
	    		if(new Date(row.startDate+' 00:00:00')<=new Date()){
	    			if(row.activityType=="COMMENT"){
	    				return "<input name='isShowVision' type='radio' onChange='drawVision(this,"+JSON.stringify(row)+");'/>";
	    			}else if(row.activityType=="FEEDBACK"){
	    				return "<input name='isShowVision' type='radio' onChange='drawVision(this,"+JSON.stringify(row)+");'/>";
	    			}else{
	    				return "<input name='isShowVision' type='radio' onChange='drawVision(this,"+JSON.stringify(row)+");'/>";
	    			}
	    		}
	    	}},
	    	{field: 'op',title: '操作',width:180,formatter:function(value,row,index){
	    		if(new Date(row.startDate+' 00:00:00')<=new Date() &&　new Date(row.endDate+' 00:00:00')>new Date()){
	    			if(row.activityType=="COMMENT"){
	    				return '<a href="/pad/comment.html?assignmentId='+row.assignmentId+'" target="_blank" class="btn btn-info btn-xs">组内互评</a>';
	    			}else if(row.activityType=="FEEDBACK"){
	    				var htmlStr = '<div class="btn-group"><button class="btn btn-info btn-xs dropdown-toggle" type="button" id="dropdownMenu'+index+'" data-toggle="dropdown">组间互评<span class="caret"></span></button><ul class="dropdown-menu" style="position:relative;" role="menu" aria-labelledby="dropdownMenu'+index+'">';
	    				$.ajax({
	    					url:'/pad/assignment/getCommentAssignmentPad?activityId='+row.id,
		    	    		async: false,
	    					success:function(data){
	    						for(var i=0;i<data.assignmentPads.length;i++){
	    							if(data.assignmentPads[i]!=null)
	    							htmlStr += '<li role="presentation"><a role="menuitem" tabindex="-1" target="_blank" href="/pad/feedback.html?assignmentPadId='+data.assignmentPads[i].id+'">'+data.assignmentPads[i].groupName+'</a></li>';
	    						}
	    					}
	    				});
	    				htmlStr +='</ul></div> <a href="/pad/edit?assignmentId='+row.assignmentId+'" target="_blank" class="btn btn-info btn-xs">回评</a>';
	    				return htmlStr;
	    			}else{
	    				return '<a href="/pad/edit?assignmentId='+row.assignmentId+'" target="_blank" class="btn btn-info btn-xs">编辑</a>';
	    			}
	    		}
	    	}}]
	});
}
var currentActivity = {};
function drawVision(dom,row){
	currentActivity = row;
	var activityId = row.id;
	if($(dom).is(':checked')){
		$.ajax({
			url:'/pad/activity/getActivityGroupVision?activityId='+activityId,
			cache:true,
			success:function(result){
				if(result.code==0){
					var visions = result.data.vision==null?"":result.data.vision.vision==null?"":result.data.vision.vision;
					$('#visions').html('');
					if(visions==""){
						$('#visions').html('无');
					}
					if(visions.indexOf("1")>-1){//编写专注度折线图
						drawFocusVision(activityId);
					}
					if(visions.indexOf("2")>-1){//编辑字数饼图
						drawGroupWordPie(activityId);
					}
					if(visions.indexOf("3")>-1){//编辑版本数柱状图
						drawGroupVersionBar(activityId);
					}
					if(visions.indexOf("4")>-1){//组内互评雷达图
						drawGroupRadar(activityId);
					}
					if(visions.indexOf("5")>-1){//组内互评社会网络图
						drawRelationship(activityId);
					}
					if(visions.indexOf("6")>-1){//组间互评雷达图
						getData(activityId);
	        			print();
					}
					if(visions.indexOf("7")>-1){//组间互评社会网络图
						drawRelationship(activityId);
					}
				}
			}
		});
	}
}
/**
 * 专注度图
 */
function drawFocusVision(activityId){
	$.ajax({
		url:'/pad/analysis/getFocus?activityId='+activityId,
		success:function(focusJson){
			if(!$('#selectTime').length>0){
				$('#visions').append('<div id="selectTime"><input id="startFilterTime" name="startFilterTime" class="date date-time"> - <input id="endFilterTime" name="endFilterTime" class="date date-time"> <input type="button" onclick="javascript:drawFocusVision(\''+activityId+'\')" value="过滤"></div>');
				$('.date-time').datetimepicker({
					autoclose: 1,
					format: 'yyyy-mm-dd hh:ii:ss',
					todayBtn:  1,
					todayHighlight: 1,
					forceParse: 1
				});
			}
			var startFilterTime = new Date($('#startFilterTime').val());
			var endFilterTime = new Date($('#endFilterTime').val());
			for(var n=0;n<focusJson.length;n++){
				$('#visions').append('<div class="echarts" id="foucs-chart'+n+'" style="height:320px;"></div>');
				var date = [];
				var data = [];
				var jsonData = focusJson[n].focus;
				var startDate = new Date(jsonData[0].time);
				var endDate = new Date(jsonData[jsonData.length-1].time);
				if(startFilterTime=="Invalid Date" && endFilterTime=="Invalid Date"&&focusJson.length>0){
					startFilterTime = new Date(jsonData[0].time);
					endFilterTime = new Date(jsonData[jsonData.length-1].time);
				}
				var index = 0;
				if(startFilterTime!="Invalid Date" && endFilterTime!="Invalid Date"){
					for(var i=startFilterTime.getTime();i<endFilterTime.getTime();i=i+1000){
						date.push(new Date(i).format("yyyy-MM-dd hh:mm:ss"));
						var myflag = true;
						for(var j=index;jsonData[j].time<i&&i<endDate.getTime();j++){
							if(jsonData[j].time-i>-1000 && jsonData[j].time-i<1000){
								data.push(jsonData[j].focus);
								myflag = false;
								break;
							}
						}
						if(myflag){
							data.push(0.0);
						}
					}
				}else{
					for (var i = 0; i < jsonData.length; i++) {
						date.push(new Date(jsonData[i].time).format("yyyy-MM-dd hh:mm:ss"));
						data.push(jsonData[i].focus);
					}
				}
				option = {
						title: {
					        text: '专注度-'+focusJson[n].user
					    },
						tooltip: {
							trigger: 'axis',
							position: function (pt) {
								return [pt[0], '1'];
							}
						},
						xAxis: {
							type: 'category',
							boundaryGap: false,
							data: date
						},
						yAxis: {
							type: 'value',
							min:0,
							max:1
						},
						series: [
							{
								name:'专注度',
								type:'line',
								itemStyle: {
									normal: {
										color: 'rgb(255, 70, 131)'
									}
								},
								data: data
							}
							]
				};
				
				var myChart = echarts.init(document.getElementById('foucs-chart'+n));
				myChart.setOption(option);
			}
		}
	});
	
}
function getData(activityId){
	$.ajax({
		url:'/pad/anyComment?activityId='+activityId+'&userid='+currentUserId,
		async: false,
		success:function(FbcommentQua){
			ctimes=FbcommentQua.commentCount;
			bctimes=FbcommentQua.becommentCount;
			score=FbcommentQua.commentScore;
			
		}
	});
	$.ajax({
		url:'/pad/anyCommentType?activityId='+activityId+'&userid='+currentUserId,
		async: false,
		success:function(commentType_){
			this.commentType=commentType_;
		}
	});
}

function print(){

	if($('#myChart').length<=0){
		$('#visions').html('<div align="center" style="width: 400px; margin:0 auto;"><h4>下面是你的评论数据雷达图:</h4><canvas id="myChart"></canvas></div>');
		$('#visions').append('<div align="center" style="width: 400px; margin:0 auto;"><h4>下面是你的评论回馈雷达图:</h4><canvas id="myChart2"></canvas></div>');
	}
	// 1 获取一个画布对象 ，也就是将要产生图标的位置
	var ctx = document.getElementById("myChart").getContext("2d");
	var ctx2 = document.getElementById("myChart2").getContext("2d");
	var labelArr = [];
	var dataArr = [];
	for(var i=0;i<commentType.length;i++){
		labelArr.push(commentType[i].typeName);
		dataArr.push(commentType[i].typeValue);
	}
	var data = {			
		    labels: ["commentTimes", "beCommentTimes", "avgScore"],
		    datasets: [
		               
		        {
		            label: currentUserName,
		            backgroundColor: "rgba(255,99,132,0.2)",
		            borderColor: "rgba(255,99,132,1)",
		            pointBackgroundColor: "rgba(255,99,132,1)",
		            pointBorderColor: "#000",
		            pointHoverBackgroundColor: "#000",
		            pointHoverBorderColor: "rgba(179,181,198,1)",
		            data: [ctimes, bctimes, score]
		        }
   
		]};
	
	var data2 = {			
		    labels: labelArr,
		    datasets: [
		               
		        {
		            label: currentUserName,
		            backgroundColor: "rgba(255,99,132,0.2)",
		            borderColor: "rgba(255,99,132,1)",
		            pointBackgroundColor: "rgba(255,99,132,1)",
		            pointBorderColor: "#000",
		            pointHoverBackgroundColor: "#000",
		            pointHoverBorderColor: "rgba(179,181,198,1)",
		            data: dataArr
		        }
		        ]};
	var myRadarChart = new Chart(ctx, {
	    type: 'radar',
	    data: data,
	    options: options
	});
	var myRadarChart2 = new Chart(ctx2, {
	    type: 'radar',
	    data: data2,
	    options: options
	});
	var options={
	    scale: {
	        reverse: false,
	        ticks: {
	            beginAtZero: false
	        },
	        type:'radialLinear'
	    } 
	  
	    
	}
	// 显示图表
	 $('#radarChar').css("display","block");
}
/**
 * 组内雷达图
 */
function drawGroupRadar(activityId){
	if($('#group-word-radar').length<=0){
		$('#visions').html('<div class="echarts" id="group-word-radar" style="height:340px;"></div>');
	}
	if($('#group-word-radar1').length<=0){
		$('#visions').append('<div class="echarts" id="group-word-radar1" style="height:340px;"></div>');
	}
	$.ajax({
		url:'/pad/analysis/getGroupRadar?activityId='+activityId,
		success:function(data){
			var radarNameData = [];
			var radarData = [];
			var legendData = [];
			if(data.radar.length>0){
				for(var i=0;i<data.radar[0].radar.length;i++){
					var tempObj = {};
					tempObj.name=data.radar[0].radar[i].question;
					tempObj.max=5;
					radarNameData.push(tempObj);
				}
				for(var i=0;i<data.radar.length;i++){
					var tempData = {};
					var tempArr = [];
					for(var j=0;j<data.radar[i].radar.length;j++){
						tempArr.push(data.radar[i].radar[j].score);
					}
					tempData.value=tempArr;
					tempData.name=data.radar[i].user;
					radarData.push(tempData);
					legendData.push(data.radar[i].user);
				}
			}
			option = {
				    tooltip: {},
				    legend: {
				        data: legendData
				    },
				    radar: {
				        // shape: 'circle',
				        indicator: radarNameData
				    },
				    series: [{
				        type: 'radar',
				        // areaStyle: {normal: {}},
				        data : radarData
				    }]
				};
			var myChart = echarts.init(document.getElementById('group-word-radar'));
			myChart.setOption(option);
		}
	});
	$.ajax({
		url:'/pad/analysis/getCourseRadar?activityId='+activityId,
		success:function(data){
			var radarNameData = [];
			var radarData = [];
			var legendData = [];
			for(var i=0;i<data.radar.length;i++){
				var tempObj = {};
				tempObj.name=data.radar[i].question;
				tempObj.max=5;
				radarNameData.push(tempObj);
			}
			var tempData = {};
			var tempArr = [];
			for(var j=0;j<data.radar.length;j++){
				tempArr.push(data.radar[j].score);
			}
			tempData.value=tempArr;
			tempData.name="班级平均值";
			radarData.push(tempData);
			legendData.push("班级平均值");
			option = {
				    tooltip: {},
				    legend: {
				        data: legendData
				    },
				    radar: {
				        // shape: 'circle',
				        indicator: radarNameData
				    },
				    series: [{
				        type: 'radar',
				        // areaStyle: {normal: {}},
				        data : radarData
				    }]
				};
			var myChart = echarts.init(document.getElementById('group-word-radar1'));
			myChart.setOption(option);
		}
	});
}
/**
 * 组内文字饼图
 */
function drawGroupWordPie(activityId){
	if($('#group-word-pie').length<=0){
		$('#visions').append('<div class="echarts" id="group-word-pie" style="height:320px;"></div>');
	}
	if($('#group-word-pie1').length<=0){
		$('#visions').append('<div class="echarts" id="group-word-pie1" style="height:320px;"></div>');
	}
	$.ajax({
		url:'/pad/analysis/getGroupWordPie?activityId='+activityId,
		success:function(data){
			var pieData = [];
			for(var i=0;i<data.pie.length;i++){
				var tempData = {};
				tempData.value = data.pie[i].wordCount;
				tempData.name = data.pie[i].user;
				pieData.push(tempData);
			}
			option = {
			    title : {
			        text: '小组成员编辑字数',
			        subtext: data.groupName,
			        x:'center'
			    },
			    tooltip : {
			        trigger: 'item',
			        formatter: "{a} <br/>{b} : {c} ({d}%)"
			    },
			    series : [
			        {
			            name: '字数编辑总量',
			            type: 'pie',
			            radius : '55%',
			            center: ['50%', '60%'],
			            data:pieData,
			            itemStyle: {
			                emphasis: {
			                    shadowBlur: 10,
			                    shadowOffsetX: 0,
			                    shadowColor: 'rgba(0, 0, 0, 0.5)'
			                }
			            }
			        }
			    ]
			};
			var myChart = echarts.init(document.getElementById('group-word-pie'));
			myChart.setOption(option);
		}
	});
	$.ajax({
		url:'/pad/analysis/getCourseWordPie?activityId='+activityId,
		success:function(data){
			var pieData = [];
			var tempData = {};
			tempData.value = data.wordCount;
			tempData.name = "班级平均";
			pieData.push(tempData);
			option = {
			    title : {
			        text: '班级平均编辑字数',
			        subtext: data.groupName,
			        x:'center'
			    },
			    tooltip : {
			        trigger: 'item',
			        formatter: "{a} <br/>{b} : {c} ({d}%)"
			    },
			    series : [
			        {
			            name: '字数编辑总量',
			            type: 'pie',
			            radius : '55%',
			            center: ['50%', '60%'],
			            data:pieData,
			            itemStyle: {
			                emphasis: {
			                    shadowBlur: 10,
			                    shadowOffsetX: 0,
			                    shadowColor: 'rgba(0, 0, 0, 0.5)'
			                }
			            }
			        }
			    ]
			};
			var myChart = echarts.init(document.getElementById('group-word-pie1'));
			myChart.setOption(option);
		}
	});
}
/**
 * 组内版本数柱状图
 */
function drawGroupVersionBar(activityId){
	if($('#group-version-bar').length<=0){
		$('#visions').append('<div class="echarts" id="group-version-bar" style="height:320px;"></div>');
	}
	if($('#group-version-bar1').length<=0){
		$('#visions').append('<div class="echarts" id="group-version-bar1" style="height:320px;"></div>');
	}
	$.ajax({
		url:'/pad/analysis/getGroupVersionBar?activityId='+activityId,
		success:function(data){
			var xAxisData = [];
			var barData = [];
			for(var i=0;i<data.bar.length;i++){
				xAxisData.push(data.bar[i].user);
				barData.push(data.bar[i].versionCount);
			}
			option = {
				title : {
			        text: '小组成员编辑版本数',
			        subtext: data.groupName,
			        x:'center'
			    },
				color: ['#3398DB'],
			    tooltip : {
			        trigger: 'axis',
			        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
			            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
			        }
			    },
			    grid: {
			        left: '3%',
			        right: '4%',
			        bottom: '3%',
			        containLabel: true
			    },
			    xAxis : [
			        {
			            type : 'category',
			            data : xAxisData,
			            axisTick: {
			                alignWithLabel: true
			            }
			        }
			    ],
			    yAxis : [
			        {
			            type : 'value'
			        }
			    ],
			    series : [
			        {
			            name:'版本数',
			            type:'bar',
			            barWidth: '60%',
			            data:barData
			        }
			    ]
			};
			var myChart = echarts.init(document.getElementById('group-version-bar'));
			myChart.setOption(option);
		}
	});
	$.ajax({
		url:'/pad/analysis/getCourseVersionBar?activityId='+activityId,
		success:function(data){
			var xAxisData = [];
			var barData = [];
			xAxisData.push("班级平均");
			barData.push(data.versionCount);
			option = {
				title : {
			        text: '班级平均编辑版本数',
			        subtext: data.groupName,
			        x:'center'
			    },
				color: ['#3398DB'],
			    tooltip : {
			        trigger: 'axis',
			        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
			            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
			        }
			    },
			    grid: {
			        left: '3%',
			        right: '4%',
			        bottom: '3%',
			        containLabel: true
			    },
			    xAxis : [
			        {
			            type : 'category',
			            data : xAxisData,
			            axisTick: {
			                alignWithLabel: true
			            }
			        }
			    ],
			    yAxis : [
			        {
			            type : 'value'
			        }
			    ],
			    series : [
			        {
			            name:'版本数',
			            type:'bar',
			            barWidth: '60%',
			            data:barData
			        }
			    ]
			};
			var myChart = echarts.init(document.getElementById('group-version-bar1'));
			myChart.setOption(option);
		}
	});
}
/**
 * 组间关系图
 */
function drawRelationship(activityId){
	if($('#group-version-bar').length<=0){
		$('#visions').append('<div class="echarts" id="group-version-relationship" style="height:320px;"></div>');
	}
	$.ajax({
		url:'/pad/getRelationship?activityId='+activityId,
		success:function(data){
			var graphData = [];
			var graphLinks = [];
			var graphSet = new Set();
			for(var i=0;i<data.length;i++){
				if(data[i].commentTimes!=0||data[i].replyTimes!=0||data[i].feedbackTimes!=0){
					graphSet.add(data[i].author);
					graphSet.add(data[i].commenter);
					var temp = {};
					temp.source = data[i].author;
					temp.target = data[i].commenter;
					temp.name="";
					if(data[i].commentTimes!=0){
						temp.name += "评论:"+data[i].commentTimes+"次；";
					}
					if(data[i].replyTimes!=0){
						temp.name += "回复:"+data[i].replyTimes+"次；";
					}
					if(data[i].feedbackTimes!=0){
						temp.name += "反馈评分:"+data[i].feedbackTimes+"次；";
					}
					temp.lineStyle={
	                    normal: {
	                        curveness: 0.1
	                    }
	                };
					temp.label={
						normal : {
							formatter: function(params, ticket, callback) {
								params.name=params.data.name;
								return params.name;
					        },
							show : true
						}
					};
					graphLinks.push(temp);
				}
			}
			for (var x of graphSet) {
				var temp = {};
				temp.name=x;
				temp.x=Math.random()*1000;
				temp.y=Math.random()*1000;
				graphData.push(temp);
			}
			console.log(JSON.stringify(graphData));
			console.log(JSON.stringify(graphLinks));
			option = {
			    title: {
			        text: '社会网络图',
			        x:'center'
			    },
			    tooltip: {},
			    animationDurationUpdate: 150,
			    animationEasingUpdate: 'quinticInOut',
			    series : [
			        {
			            type: 'graph',
			            layout: 'none',
			            symbolSize: 50,
			            roam: true,
			            label: {
			                normal: {
			                    show: true
			                }
			            },
			            edgeSymbol: ['circle', 'arrow'],
			            edgeSymbolSize: [4, 10],
			            edgeLabel: {
			                normal: {
			                    textStyle: {
			                        fontSize: 10
			                    }
			                }
			            },
			            data: graphData,
			            // links: [],
			            links: graphLinks,
			            lineStyle: {
			                normal: {
			                    opacity: 0.9,
			                    width: 1,
			                    curveness: 0
			                }
			            }
			        }
			    ]
			};
			var myChart = echarts.init(document.getElementById('group-version-relationship'));
			myChart.setOption(option);
		}
	});
}
$(function(){
    /**
	 * 时间对象的格式化;
	 */  
    Date.prototype.format = function(format) {  
        /*
		 * eg:format="yyyy-MM-dd hh:mm:ss";
		 */  
        var o = {  
            "M+" : this.getMonth() + 1, // month
            "d+" : this.getDate(), // day
            "h+" : this.getHours(), // hour
            "m+" : this.getMinutes(), // minute
            "s+" : this.getSeconds(), // second
            "q+" : Math.floor((this.getMonth() + 3) / 3), // quarter
            "S" : this.getMilliseconds()  
            // millisecond
        }  
      
        if (/(y+)/.test(format)) {  
            format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));  
        }  
        for (var k in o) {  
            if (new RegExp("(" + k + ")").test(format)) {  
                format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));  
            }  
        }  
        return format;  
    }  
});
